﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using System.IO;
using System.Diagnostics;
using IronPython.Runtime;


namespace CSharpCallPython
{
    class Program
    {
        static void Main(string[] args)
        {
            //string pythonFileName = "PClass.py";
            string pythonFileName = "PythonCallCSharp.py";
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start(); //  开始监视代码运行时间   
            ScriptRuntime sr = Python.CreateRuntime();
            FileInfo fi = new FileInfo("TestForPCC.dll");

            ScriptScope scope = sr.UseFile(pythonFileName);
            PythonFunction pf = scope.GetVariable<PythonFunction>("showForm");
            ScriptEngine engine = scope.Engine;

            if (engine.Operations.IsCallable(pf))
                engine.Operations.Invoke(pf, "Hello Python!!!!");
            //for (int i = 0; i < 1000; i++)
            //{
            //    if (engine.Operations.IsCallable(pf))
            //        Console.WriteLine(engine.Operations.Invoke(pf, "Hello Python!!!!"));
            //}

            stopwatch.Stop(); //  停止监视           
            TimeSpan timespan = stopwatch.Elapsed; //  获取当前实例测量得出的总时间               
            double milliseconds = timespan.TotalMilliseconds;  //  总毫秒数
            Console.WriteLine(milliseconds);
            Console.ReadKey();
        }
    }
}
